define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'my_salary/index' + location.search,
                    detail_url: 'my_salary/detail',
                    preview_url: 'my_salary/preview',
                    import_url: 'my_salary/import',
                    table: 'my_salary',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'admin.nickname', title: '姓名', operate:'LIKE'},
                        {field: 'salary.name', title: '工资清单名称', operate:false},
                        {field: 'salary.start_time', title: '统计日期开始时间',datetimeFormat:'YYYY-MM-DD', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'salary.end_time', title: '统计日期结束时间',datetimeFormat:'YYYY-MM-DD', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'create_time', title: '添加时间', operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'),
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '查看统计数据',
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'my_salary/statistics',
                                },
                                // {
                                //     name: 'detail',
                                //     text: '查看',
                                //     icon: '',
                                //     classname: 'btn btn-xs btn-primary btn-dialog',
                                //     url: 'my_salary/detail',
                                // },
                                {
                                    name: 'preview',
                                    text: '查看工资条',
                                    icon: '',
                                    extend: 'data-area=\'["90%", "35%"]\'',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'my_salary/preview',
                                },
                            ],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        gongzi: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'my_salary/gongzi' + location.search,
                    table: 'my_salary',
                }
            });
            var columns = [];
            columns.push({checkbox: true});
            columns.push({field: 'admin.nickname', title: '姓名', operate:'LIKE'});
            columns.push({field: 'benchmark.salary_benchmark_item_id', title: '单选基准项', searchList: function (column) {
                    //重点
                    return Template('sourcetpl', {});
            }});
            for (var i=0;i<tpls.length;i++){
                columns.push({field: tpls[i], title: tpls[i], operate:false, sortable:true})
            }
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                columns: columns
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            table.bootstrapTable('hideColumn','benchmark.salary_benchmark_item_id');
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        preview: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
